package org.steven.crm.app.api.processor;

import org.steven.crm.app.api.LocalDataCache;
import org.steven.crm.app.api.processor.base.BaseProcessor;
import org.steven.crm.core.service.area.AreaService;

/**
 * @Author wuzw
 * @Date 2023/6/27 10:50
 * @Version 1.0
 */
public class AreaProcessor extends BaseProcessor {
    private static AreaService service = new AreaService();

    public void readAction() throws Exception {
        setObjectData(service.read(getStringData("id")));
    }

    public void getProvincesAction() throws Exception {
        setObjectData(LocalDataCache.getInstance().getProvinces());
    }

    public void getProvinceCitiesAction() throws Exception {
        setObjectData(LocalDataCache.getInstance().getCitiesByProvinceId(getStringData("provinceId")));
    }

    public void getCityTownsAction() throws Exception {
        setObjectData(LocalDataCache.getInstance().getTownsByCityId(getStringData("cityId")));
    }

    public void readByPidAction() throws Exception {
        setObjectData(service.readByPid(getStringData("pid"), "id,name", true));
    }

    public void readAreaTreeByIdAction() throws Exception {
        setObjectData(service.readAreaTreeById(getStringData("id"), "id, name"));
    }

    public void readByPidExcludeChildrenAction() throws Exception {
        setObjectData(service.readByPid(getStringData("pid"), "id,name", false));
    }

    public void makeTreeAction() throws Exception {
        setObjectData(LocalDataCache.getInstance().getAreaTree());
    }

}
